/*-----------------------------------------------------------------------------
* @Description:     信息登记-登记详情
* @Version:         1.0.0
* @author:          gts(616603151@qq.com)
* @date             2017.11.14
* ==NOTES:=============================================
* 
* ---------------------------------------------------------------------------*/
$(function(){
    /**
     * 初始化提示信息、验证表单
     */
    Pagination(1);

    /**
     * 分页
     */
    $('#pageLimit').bootstrapPaginator({
        //currentPage: 3,
        totalPages: $('.pageDataCount').val(),
        size: "small",
        bootstrapMajorVersion: 3,
        alignment: "right",
        numberOfPages: 5,
        itemTexts: function (type, page, current) {
            switch (type) {
                case "first": return "首页";
                case "prev": return "<";
                case "next": return ">";
                case "last": return "末页";
                case "page": return page;
            }
        },
        onPageClicked: function (event, originalEvent, type, page) {
            var
                form = $(".J_searchForm").serializeObject();

            Pagination(page, form);  
        }
    });
     /**
     * 分页刷标题
     */
    function Pagination(page, extraData){

        var
            currentPage = page,            
            str = '',
            recordId = $("input[name='id']").val(),
            data = {
                page: currentPage,
                recordId: recordId
            };
        jQuery.extend(data, extraData);

        $.ajax({
            type: jQuery.url.InformationRegisterManagement.detailTitle.type,
            url: jQuery.url.InformationRegisterManagement.detailTitle.url,
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            data: data,     //JSON.stringify
            dataType: "json",
            success: function (rs) {
               if( rs.code == 0){ 
                    $('#J_template').empty();
                    $.each(rs.list, function(index, item){
                         str += '<tr data-id="'+ item.id +'">\
                                    <td>'+ item.xuhao +'</td>\
                                    <td>'+ item.name +'</td>\
                                    <td>'+ item.number +'</td>\
                                    <td>\
                                        <a href="/admin/record/person/'+ recordId +'/'+ item.id +'" class="label-info"><i class="fa fa-book"></i>&nbsp;详情</a>\
                                    </td>\
                                </tr>';
                    }); 
                    $('#J_template').append(str);
                }else{                
                    location.reload();
                }
            },
            error: function (message) {
                // location.reload();
            }
        });
    }
     
    /**
     * 列表点击搜索事件
     * @param  {[type]} ){                     }
     * @return {[type]}     [description]
     */
    $(".J_search").click(function(){
        var
            form = $(".J_searchForm").serializeObject();

       
        Pagination(1, form);
    });

})  

   